package com.gwz.bus.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gwz.bus.domain.Goods;
import com.gwz.bus.mapper.GoodsMapper;
import com.gwz.bus.service.GoodService;
import com.gwz.bus.vo.CustomerVo;
import com.gwz.bus.vo.GoodsVo;
import com.gwz.sys.utils.DataGridView;

@Service
@Transactional
public class GoodServiceImpl implements GoodService {

	@Autowired
	private GoodsMapper goodsMapper;
	
	@Override
	public DataGridView queryAllGoods(GoodsVo goodsVo) {
		Page<Object> page = PageHelper.startPage(goodsVo.getPage(), goodsVo.getLimit());
		List<Goods> data = goodsMapper.queryAllGoods(goodsVo);
		return new DataGridView(page.getTotal(), data);
	}
	
	@Override
	public void addGoods(GoodsVo goodsVo) {
		goodsMapper.insertSelective(goodsVo);
	}

	@Override
	public void updateGoods(GoodsVo goodsVo) {
		goodsMapper.updateByPrimaryKeySelective(goodsVo);
	}

	@Override
	public void deleteGoods(GoodsVo goodsVo) {
		goodsMapper.deleteByPrimaryKey(goodsVo.getId());
	}

	@Override
	public void batchDelete(GoodsVo goodsVo) {
		Integer[] ids = goodsVo.getIds();
		for (Integer id : ids) {
			goodsMapper.deleteByPrimaryKey(id);
		}
	}

	@Override
	public List<Goods> loadGoodsByProviderId(Integer providerId) {
		return goodsMapper.queryGoodsByProviderId(providerId);
	}

}

